package com.fs.service.Impl;

import com.fs.dto.ProductTagAddDTO;
import com.fs.entity.ProductTag;
import com.fs.mapper.ProductTagMapper;
import com.fs.service.ProductTagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 商品标签业务实现
 */
@Service
@Slf4j
public class ProductTagServiceImpl implements ProductTagService {

    @Autowired
    private ProductTagMapper tagMapper;

    @Override
    public void addTag(ProductTagAddDTO dto) {
        ProductTag tag = new ProductTag();
        BeanUtils.copyProperties(dto, tag);
        tag.setCreateTime(LocalDateTime.now());
        tagMapper.insert(tag);
        log.info("[ProductTagService] 添加标签成功 productId={} tag={}", dto.getProductId(), dto.getTagName());
    }

    @Override
    public void deleteById(Long id) {
        tagMapper.deleteById(id);
        log.info("[ProductTagService] 删除标签 id={}", id);
    }

    @Override
    public void deleteByProductIds(List<Long> productIds) {
        if (productIds == null || productIds.isEmpty()) return;
        tagMapper.deleteByProductIds(productIds);
        log.info("[ProductTagService] 删除商品相关标签 productIds={}", productIds);
    }

    @Override
    public List<ProductTag> listByProductId(Long productId) {
        return tagMapper.selectByProductId(productId);
    }
}
